package com.furongji.education.controller.api;

import com.furongji.common.result.Result;
import com.furongji.education.utils.AliyunOssOperator;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Tag(name = "上传文件")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/oss")
public class OssApiController {

    private final AliyunOssOperator aliyunOssOperator;

    @Operation(summary = "上传图片")
    @PostMapping("/upload")
    public Result uploadAvatar(MultipartFile file) throws Exception {
        String url = aliyunOssOperator.upload(file.getBytes(), file.getOriginalFilename());
        return Result.success(url);
    }
}
